package mop.bootstrap;

import java.util.LinkedList;
import java.util.List;
import mop.controller.*;
import mop.gui.GUI;
import mop.model.World;

/**
 * Starts our task manager (v2).
 * 
 * @author  MOP Team 7
 */
public class Main
{
   /**
    * Simple bootstrap procedure.
    * 
    * 1. creates world
    * 2. reads xml
    * 3. creates controllers
    * 4. creates gui
    * 5. shows gui
    * 
    * @param    args
    *           the command line arguments
    */
    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable()
            {
                public void run()
                {
                    // 1. creates world
                    World world = new World();
                    
                    // 2. reads xml
                    TaskplannerXMLReader reader = new TaskplannerXMLReader(world);
                    String wd = System.getProperty("user.dir");
                    JFileChooser fc = new JFileChooser(wd);
                    int rc = fc.showDialog(null, "Select Data File");
                    if (rc == JFileChooser.APPROVE_OPTION)
                        reader.process(fc.getSelectedFile());
                    else
                        System.exit(0);

                    // 3. creates controllers
                    List<UseCaseController> controllers = new LinkedList<UseCaseController>();
                    controllers.add(new AssignTaskToProjectController(world));
                    controllers.add(new ChangeClockController(world));
                    controllers.add(new CreateProjectController(world));
                    controllers.add(new CreateResourceController(world));
                    controllers.add(new CreateTaskController(world));
                    controllers.add(new CreateUserController(world));
                    controllers.add(new FocusWorkController(world));
                    controllers.add(new LoginUserController(world));
                    controllers.add(new MakeResourceReservationController(world));
                    controllers.add(new ModifyTaskDetailsController(world));
                    controllers.add(new RemoveProjectController(world));
                    controllers.add(new RemoveTaskController(world));
                    controllers.add(new UpdateTaskStatusController(world));

                    // 4. creates gui
                    GUI gui = new GUI(controllers);
                    
                    // 5. shows gui
                    gui.showLoginDialog();
                }
            });
    }
}
